/*
TASK:msquare
ID:luongho3
LANG:C++
*/
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
#define SIZE 9
#define MAX 50000
ifstream fin("msquare.in");
ofstream fout("msquare.out");
int fac[10] = {1,1,2,3,24,120,720,5040,40320,362880};
int mark[MAX];
int prev[MAX];
char t_type[MAX];
struct conf {
       int up[5];
       int down[5];
       int id;
};
typedef queue<conf> cqueue;
cqueue q;
conf iconf;
conf target;
conf tconf;
void getId(conf &co) {
     int per[9];
     int i,j;
     for (i=1;i<=4;++i) {
         per[i] = co.up[i];
     }
     for (i=5;i<=8;++i) {
         per[i] = co.down[9-i];
     }
     int num = 0;
     for (i=1;i<=8;++i) {
         num = num + (per[i]-1)*fac[8-i];
         for (j=i+1;j<=8;++j) {
             if (per[j]>per[i]) {
                per[j] = per[j]-1;
             }
         }
     }
     num = num+1;
     co.id = num;
}
conf move_a(conf co) {
     int i;
     for (i=1;i<=4;++i) {
         int t = co.up[i];
         co.up[i] = co.down[i];
         co.down[i] = t;
     }
     getId(co);
     return co;
}
conf move_b(conf co) {
     int i;
     co.up[0] = co.up[4];
     co.down[0] = co.down[4];
     for (i=4;i>=1;--i) {
         co.up[i] = co.up[i-1];
         co.down[i] = co.down[i-1];
     }
     getId(co);
     return co;
}
conf move_c(conf co) {
     int t = co.up[2];
     co.up[2] = co.down[2];
     co.down[2] = co.down[3];
     co.down[3] = co.up[3];
     co.up[3] = t;
     getId(co);
     return co;
}
void read_target() {
     int i;
     for (i=1;i<=4;++i) {
         fin >> target.up[i];
     }
     for (i=4;i>=1;--i) {
         fin >> target.down[i];
     }
     getId(target);
}
void set_iconf() {
     int i;
     for (i=1;i<=4;++i) {
         iconf.up[i]=i;
     }
     for (i=1;i<=4;++i) {
         iconf.down[i] = 9-i;
     }
     iconf.id = 1;
}
int nstep = 0;
string steps = "";
int main() {
    read_target();
    set_iconf();
    q.push(iconf);
    while (!q.empty()) {
          tconf = q.front();
          q.pop();
          if (tconf.id == target.id) {
             break;
          }
          else {
               conf temp = move_a(tconf);
               if (mark[temp.id]!=1) {
                  q.push(temp);
                  mark[temp.id]=1;
                  prev[temp.id]=tconf.id;
                  t_type[temp.id]='A';
               }
               
               temp = move_b(tconf);
               if (mark[temp.id]!=1) {
                  q.push(temp);
                  mark[temp.id]=1;
                  prev[temp.id]=tconf.id;
                  t_type[temp.id]='B';
               }
               
               temp = move_c(tconf);
               if (mark[temp.id]!=1) {
                  q.push(temp);
                  mark[temp.id]=1;
                  prev[temp.id]=tconf.id;
                  t_type[temp.id]='C';
               }
          }
    }
    while (tconf.id!=iconf.id) {
          steps += t_type[tconf.id];
          nstep = nstep + 1;
          tconf.id = prev[tconf.id];
    }
    fout <<nstep << "\n";
    int i;
    int j=0;
    for (i=steps.length()-1;i>=0;--i) {
        if (j==60) {
           fout <<"\n";
           j=0;
        }
        fout <<steps[i];
        ++j;
    }
    fout <<"\n";
    return 0;
}
